package com.sms.plateform.common.util;

/**
 * <p>
 * 随机整数发生器
 * </p>
 * 
 * @author Xuepeng.Duan
 * @version 1.0
 * @created 2008-1-14
 */
public class RandomInt {

	private static final int BUFFER_SIZE = 101;

	private static double[] buffer = new double[BUFFER_SIZE];

	private int low;

	private int high;

	static {
		for (int i = 0; i < BUFFER_SIZE; i++) {
			buffer[i] = java.lang.Math.random();
		}
	}

	public RandomInt(int low, int high) {
		this.low = low;
		this.high = high;
	}

	private static double nextRandom() {
		int pos = (int) (java.lang.Math.random() * BUFFER_SIZE);
		if (pos == BUFFER_SIZE)
			pos = BUFFER_SIZE - 1;
		double r = buffer[pos];
		buffer[pos] = java.lang.Math.random();
		return r;
	}

	/**
	 * 得到随机数
	 *
	 * @return
	 *
	 */
	public int draw() {
		int r = low + (int) ((high - low + 1) * nextRandom());
		return r;
	}
	
	public static void main(String[] args) {
		RandomInt random = new RandomInt(0, 100000);
		System.out.println(random.draw());
	}
}
